package org.jeese.modules.demo.web;

import java.util.List;
import java.util.Map;

import org.jeese.modules.demo.entity.Book;
import org.jeese.modules.demo.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;

@RestController
@RequestMapping("book/*")
public class DataController {
	@Autowired
	private BookService bookService;

	/**
	 * 列表
	 * @return
	 */
	@RequestMapping(value = "list", method = RequestMethod.GET)
	public List<Book> list() {
		return bookService.listAll();
	}
	
	/**
	 * 分页
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@RequestMapping(value = "page", method = RequestMethod.GET)
	public List<Book> page(Integer pageNo, Integer pageSize) {
		PageInfo<Book> page = bookService.page(pageNo, pageSize);
		return page.getList();
	}
	
	@RequestMapping(value = "page1", method = RequestMethod.GET)
	public List<Book> page1(Integer pageNo, Integer pageSize, String name) {
		PageInfo<Book> page = bookService.page(pageNo, pageSize, name);
		return page.getList();
	}
	
	@RequestMapping(value = "page2", method = RequestMethod.GET)
	public PageInfo<Book> page2(Integer pageNo, Integer pageSize, String name) {
		PageInfo<Book> page = bookService.page(pageNo, pageSize, name);
		return page;
	}
	
	@RequestMapping(value = "add", method = RequestMethod.POST)
	public Map<String, Object> add(Book book) {
		return bookService.add(book);
	}
	
	@RequestMapping(value = "edit", method = RequestMethod.POST)
	public Map<String, Object> edit(Book book) {
		return bookService.edit(book);
	}
	
	@RequestMapping(value = "delete", method = RequestMethod.POST)
	public Map<String, Object> delete(Long id) {
		return bookService.delete(id);
	}
}
